/**
 * [122] 买卖股票的最佳时机 II
 *
 * @format
 * @lc app=leetcode.cn id=122 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} prices
 * @return {number}
 */
// 贪心算法
var maxProfit = function (prices) {
    return prices.reduce((sum, price, i) => (price > prices[i - 1] ? sum + price - prices[i - 1] : sum), 0)
    // const forecast = []
    
    // for (let i = 1; i < prices.length; i++) {
    //     forecast.push(prices[i] - prices[i - 1])
    // }
    // let money = 0
    // for (let i = 0; i < forecast.length; i++) {
    //     if (forecast[i] > 0) money += forecast[i]
    // }
    // return money
}
// @lc code=end
